gui/macOS: Fix accountIdFromDomainId
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 10 Feb 2025 07:07:05 +0000 (15:07 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 10 Feb 2025 11:01:06 +0000 (12:01 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileproviderdomainmanager_mac.mm

index d1660810a18afd9edfeaba7f21f5f256382f5176..1c033554d06d4053fc2d02092d8b899d82dea056 100644 (file)
@@ -104,7 +104,21 @@ QString accountIdFromDomainId(const QString &domainId)
 
 QString accountIdFromDomainId(NSString * const domainId)
 {
-    return accountIdFromDomainId(QString::fromNSString(domainId));
+    auto qDomainId = QString::fromNSString(domainId);
+    if (!qDomainId.contains('-')) {
+        return qDomainId.replace("(.)", ".");
+    }
+    // Using slashes as the replacement for illegal chars was unwise and we now have to pay the
+    // price of doing so...
+    const auto accounts = OCC::AccountManager::instance()->accounts();
+    for (const auto &accountState : accounts) {
+        const auto account = accountState->account();
+        const auto convertedDomainId = domainIdentifierForAccount(account);
+        if (convertedDomainId == qDomainId) {
+            return account->userIdAtHostWithPort();
+        }
+    }
+    Q_UNREACHABLE();
 }
 
 API_AVAILABLE(macos(11.0))